# Multi-stage build for Flink Java application

# Stage 1: Build with Maven
FROM maven:3.8.6-eclipse-temurin-11 AS builder

WORKDIR /app

# Copy POM first for dependency caching
COPY pom.xml .

# Download dependencies
RUN mvn dependency:go-offline

# Copy source code
COPY src ./src

# Build the application (creates fat JAR)
RUN mvn clean package -DskipTests

# Stage 2: Runtime with Flink
FROM flink:1.18.0-java11

# Copy the built JAR from builder stage
COPY --from=builder /app/target/flink-llm-behavior-analysis-1.0.0.jar /opt/flink/usrlib/

# Set environment variables (can be overridden at runtime)
ENV KINESIS_STREAM_NAME=browse-events \
    AWS_REGION=us-east-1 \
    KINESIS_ENDPOINT=http://localstack:4566 \
    POSTGRES_HOST=postgres \
    POSTGRES_PORT=5432 \
    POSTGRES_DB=browse_data \
    POSTGRES_USER=admin \
    POSTGRES_PASSWORD=admin123 \
    LLM_PROVIDER=deepseek \
    LLM_API_KEY="" \
    LLM_API_URL=https://api.deepseek.com/v1/chat/completions \
    LLM_MODEL=deepseek-chat \
    LLM_TIMEOUT=30

# The default command will be provided by docker-compose
# (either jobmanager or taskmanager)
